package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LWaybill;
import com.ruoyi.system.service.ILWaybillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 清运单主Controller
 *
 * @author zyb
 * @date 2022-01-11
 */
@RestController
@RequestMapping("/system/waybill")
public class LWaybillController extends BaseController
{
    @Autowired
    private ILWaybillService lWaybillService;

    /**
     * 查询清运单主列表
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:list')")
    @GetMapping("/list")
    public TableDataInfo list(LWaybill lWaybill)
    {
        startPage();
        List<LWaybill> list = lWaybillService.selectLWaybillList(lWaybill);
        return getDataTable(list);
    }

    /**
     * 导出清运单主列表
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:export')")
    @Log(title = "清运单主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LWaybill lWaybill)
    {
        List<LWaybill> list = lWaybillService.selectLWaybillList(lWaybill);
        ExcelUtil<LWaybill> util = new ExcelUtil<LWaybill>(LWaybill.class);
        util.exportExcel(response, list, "清运单主数据");
    }

    /**
     * 获取清运单主详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:query')")
    @GetMapping(value = "/{billid}")
    public AjaxResult getInfo(@PathVariable("billid") Long billid)
    {
        return AjaxResult.success(lWaybillService.selectLWaybillByBillid(billid));
    }

    /**
     * 新增清运单主
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:add')")
    @Log(title = "清运单主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LWaybill lWaybill)
    {
        return toAjax(lWaybillService.insertLWaybill(lWaybill));
    }

    /**
     * 修改清运单主
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:edit')")
    @Log(title = "清运单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LWaybill lWaybill)
    {
        return toAjax(lWaybillService.updateLWaybill(lWaybill));
    }

    /**
     * 删除清运单主
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:remove')")
    @Log(title = "清运单主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billids}")
    public AjaxResult remove(@PathVariable Long[] billids)
    {
        return toAjax(lWaybillService.deleteLWaybillByBillids(billids));
    }


    @GetMapping(value = "/billcode")
    public AjaxResult getBillCode()
    {
        return AjaxResult.success(lWaybillService.getBillCode());
    }

}
